//
//  JHNetWorkTools.m
//  OC中的网络封装
//
//  Created by apple on 16/5/25.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "JHNetWorkTools.h"

@implementation JHNetWorkTools

+ (instancetype)sharedTools{
    static JHNetWorkTools *tools;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        tools = [[JHNetWorkTools alloc]init];
        tools.responseSerializer.acceptableContentTypes = [tools.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
    });
    return tools;
}
- (void)requestMethod:(HTTPMethods)method urlString:(NSString *)urlString parameters:(id)parameters finished:(void (^)(id, NSError *))finished{

    if (method == GET){
    //调用GET
        [self  GET:urlString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            finished(responseObject,nil);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            finished(nil,error);
        }];
    }else{
        [self  POST:urlString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            finished(responseObject,nil);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            finished(nil,error);
        }];

    
    }

}
@end
